
#include "thunderskyfall.h"
#include "resourcemanager.h"
#include "gamemanager.h"
#include "frameanimation.h"
#include "CCSkeletalSprite.h"
#include "gamedatamanager.h"
#include "army.h"
#include "unit.h"
#include "gamescene.h"

#define __super         SkyFallBullet

ThunderSkyFallBullet::ThunderSkyFallBullet(
		Army *targetArmy,
		EquipmentAttribute *attr,
		GameScene *scene): __super(targetArmy, attr, scene) {
	_damageType = GDM->getWeaponDamageType(bulletAttribute->projectileType);

	float x = _targetArmy->frontLinePosition;
	float y = ROWS_PER_LINE / 2 * GRID_HEIGHT + FORMATION_MARGIN;

	dst = ccp(x, y);
	position = dst;
}

ThunderSkyFallBullet::~ThunderSkyFallBullet() {
}

void ThunderSkyFallBullet::init() {
	_bolt = RM->createAnimation("fx_thunder_fall", position);
	_bolt->setAnchorPoint(ccp(0.5f, 0.0f));
	_bolt->setRotation(-20.0f);
	_bolt->setLoop(false);

	_gameNodeContainer->addNode(_bolt);
}

void ThunderSkyFallBullet::createHitEffect() {
	for (int i = 0; i < ROWS_PER_LINE; i++) {
		CCPoint pos = ccp(dst.x, i * GRID_HEIGHT + FORMATION_MARGIN);
		FrameAnimation *fxHit = RM->createAnimation("fx_thunder_hit", pos);
		fxHit->setLoop(false);
		fxHit->setAnchorPoint(ccp(0.5f, 0.0f));
		fxHit->setZOrder(static_cast<int>(GM->screenSize.height - pos.y));

		_managedGameNodeInfo.node = fxHit;
		_gameNodeContainer->addOneTimeNode(_managedGameNodeInfo);
	}
}

void ThunderSkyFallBullet::updateBolt(float ticks) {
	_bolt->update(ticks);
}

bool ThunderSkyFallBullet::isHitTarget() {
	return _bolt->isFinished();
}
